package org.jypj.dev.controller;

import com.alibaba.fastjson.JSONObject;
import org.jypj.dev.vo.BaseInfo;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseController {

    private static ThreadLocal<ServletRequest> currentRequest = new ThreadLocal<ServletRequest>();
    private static ThreadLocal<ServletResponse> currentResponse = new ThreadLocal<ServletResponse>();

    @ModelAttribute
    protected void initReqAndRep(HttpServletRequest request, HttpServletResponse response) {
        currentRequest.set(request);
        currentResponse.set(response);
    }

    protected HttpServletRequest request() {
        return (HttpServletRequest) currentRequest.get();
    }

    protected HttpServletResponse response() {
        return (HttpServletResponse) currentResponse.get();
    }


    protected BaseInfo getCurrentBaseInfo() {
        BaseInfo baseInfo = (BaseInfo) request().getSession().getAttribute("baseInfo");
        return baseInfo;
    }
}
